﻿using Cofe.Core.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Cofe.Core.Filter
{
    public abstract class FilterAttribute : Attribute
    {
        public static FilterAttribute GetFilterAttribute(Type filterType)
        {
            var faArray = AttributeUtils<FilterAttribute>.GetCustomAttributes(filterType);
            if (faArray.Count() == 0)
                throw new ArgumentException("Filter is not decorated by FilterAttribute.");
            var fa = faArray.First() as FilterAttribute;
            return fa;
        }

        internal static FilterAttribute GetFilterAttribute(IFilter filter)
        {
            return GetFilterAttribute(filter.GetType());
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="name"></param>
        /// <param name="priority">Default = 0, higher priority run first.</param>
        protected FilterAttribute(string name, int priority)
        {
            FilterName = name;
            Priority = priority;
        }

        public string FilterName { get; private set; }
        public int Priority { get; private set; }
    }

    public class EntryFilterAttribute : FilterAttribute
    {
        public EntryFilterAttribute(string name, int priority = 0)
            : base(name, priority)
        {
        }
    }

    public class OptionFilterAttribute : FilterAttribute
    {
        public OptionFilterAttribute(string name, int priority = 0)
            : base(name, priority)
        {
        }
    }
}
